package com.shiyang.factory.simplefactory.pizzastore;

import com.shiyang.factory.simplefactory.pizzastore.pizza.CheesePizza;
import com.shiyang.factory.simplefactory.pizzastore.pizza.GreekPizza;
import com.shiyang.factory.simplefactory.pizzastore.pizza.Pizza;

/**
 * @author shiyang date: 2020/9/7
 */
// 简单工厂类
public class SimpleFactory {

    // 根据orderType 返回对应的Pizza对象
    // 简单工厂模式 也叫 静态工厂模式 可以把方法改为静态方法static
    public Pizza createPizza(String orderType) {
        Pizza pizza = null;
        System.out.println("使用简单工厂模式~~");
        if (orderType.equals("greek")) {
            pizza = new GreekPizza();
            pizza.setName("希腊披萨");
        } else if (orderType.equals("cheese")) {
            pizza = new CheesePizza();
            pizza.setName("奶酪披萨");
        }

        return pizza;
    }
}
